<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<%@ include file="/WEB-INF/jsp/inc/taglibs.jsp"%>
	<%@ include file="/WEB-INF/jsp/inc/meta.jsp"%>
<script type="text/javascript" src="${approot}/resource/jquery/validate/jquery.validate.js"></script>
   <link href="${approot}/resource/jquery/validate/jquery.validate.css" rel="stylesheet" type="text/css" />
   <link href="${approot}/resource/jquery/validate/style.css" rel="stylesheet" type="text/css" />
        
        <script type="text/javascript">
        function do_edit()
        {   
            var count=0;
            var ids="";
            $('input[name=ids]:checked').each(function(){
                count=count+1;
                ids=ids+$(this).attr("value")+"_";
            })
            if(count==0)
            {
                alert("请至少选择一个角色");
                return false;
            }
           // alert(jsons);
           // alert(ids);
            edit_user(ids);
        }


        function edit_user(ids){
 	       $.ajax({
 		   	url:'${approot}/admin/user/add_role/'+ids,
 		   	dataType: 'json',
 		   	contentType: 'application/json',
 			//data:jsons,
 			type:'post',
 			beforeSend:function(){
 			  // $('#main').disabled='true';
 			},
 			error:function(request){
 				//alert(S);
 			},
 			success:function(data){
 			  // if(data.msg=="error")
 			  // {
 	 			//   alert('角色分配失败');
 			 //  }
 			 //  if(data.msg=="succ")
 			 //  {
 				  alert('角色分配成功');
 				  location.href="${approot}/admin/user/right/${deptid}";
 			  // }
 			}
 		   });
 	}
        </script>
        
        <script type="text/javascript">
        function checkAll(val){
            //alert(val);
            if(val)
              $('input[name=ids]').each(function(){
                   $(this).attr('checked',true);
              })
             else
            	 $('input[name=ids]').each(function(){
                     $(this).attr('checked',false);
                })  
           }
        
        </script>
   
</head>  
  <body style="background:#E8F5FE; padding:15px 18px;" class="scroll_r">
<div id="right_w"><p>当前位置：系统管理 >>用户角色分配</p></div>

<form method="post" action="${approot}/admin/user/edit" id="user">
  <table border="0" cellpadding="0" cellspacing="1" width="92%" align="center" class="tab_l">
    <tr>
      <td><b>请按要求填写：</b></td>
      <td align="right">带<span style="color:#ff0000;">*</span>为必填</td>
    </tr>
  </table>
  <table border="0" cellpadding="0" cellspacing="1" width="92%" align="center" id="add_tab">
  <tr>
   <th colspan="3"><span style="color:#ff0000; margin:0;">*</span>选择角色<input type="checkbox" name="" onclick="checkAll(this.checked)">  </th>
 </tr><tr><c:forEach items="${roles}" var="role" varStatus="s">  <td align="left" <c:if test="${fn:length(roles)==(s.index+1)}">colspan="${4-(fn:length(roles)-s.index) }"</c:if>>
   
   <input type="checkbox" name="ids" value="${role.id}" <c:if test='${fn:contains(user.roleIDS,role.id)}'>checked</c:if>>${role.name}
    
      
   </td>
   <c:if test="${(s.index+1)%3 == 0}"></tr><tr></c:if>
   </c:forEach>
  </tr>
  
 </table>
  <p id="tab_but">
   <input type="button" value="提 交"  onclick="return do_edit();">
   <input type="button" value="返回" onclick="history.go(-1)">
   </p>
</form>
</body>
</html>
